package Thread;

import java.util.concurrent.Semaphore;

// 信号量
public class Demo31 {
    public static void main(String[] args) throws InterruptedException {
        // 构造方法中设定有几个资源
        Semaphore semaphore = new Semaphore(3);

        // P 操作，申请资源
        semaphore.acquire();
        System.out.println("申请资源");
        semaphore.acquire();
        System.out.println("申请资源");
        semaphore.acquire();
        System.out.println("申请资源");
        semaphore.acquire();
        System.out.println("申请资源");
        // V 操作，释放资源
        semaphore.release();


    }
}
